{{define "/chapter3/json.html"}}
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="/static/js/jquery.min.js"></script>
</head>

<body>
    <form>
        <input type="text" id="name"><br>
        <input type="text" id="age"><br>
        <input type="submit" value = "提交" id="add_btn">
    </form>

    <script>
        var addbtn = document.getElementById("add_btn")
        addbtn.onclick = function () {
            var name = document.getElementById("name").value
            var age = document.getElementById("age").value

            $.ajax({
                url:"/chapter3/getjson",
                type:"POST",
                data:JSON.stringify({
                    "name":name,
                    "age":age,
                }),
                contentType:"application/json",
                dataType:"json",
                success:function(data) {
                    alert(data.code)
                    alert(data.ok)
                },
                failed: function (data) {
                    alert("服务器错误")
                }
            })
        }
    </script>
</body>

</html>
{{end}}